﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MedicalDB
{
    public partial class Configurare : UserControl
    {
        private string limba;
        private FormDBMedical instance;
        public Configurare(string limba, FormDBMedical instance)
        {
            InitializeComponent();
            Rename(limba);
            this.limba = limba;
            this.instance = instance;

            string xmlFile = @"C:\Configurare.xml";
            XMLParser xmlParser = new XMLParser(xmlFile);
            Dictionary<string,string> namesForm = xmlParser.ExtractAttributePairs("Configurare", string.Empty, string.Empty, "name","formula");


            tbServerIP.Text = namesForm["ServerIP"];
	        tbServerPort.Text = namesForm["ServerPort"];	      
            tbFTPIP.Text = namesForm["FTPIp"];
	        tbFTPUser.Text = namesForm["FTPUser"];
	        mtFTPParola.Text = namesForm["FTPParola"];
            tbFTPPort.Text = namesForm["FTPPort"];

            List<string> namesForm2 = xmlParser.ExtractAttribute("Limbi", string.Empty, string.Empty, "name");

            foreach (string s in namesForm2)
                cbLimba.Items.Add(s);

            cbLimba.SelectedItem = limba;

        }

        private void btModifica_Click(object sender, EventArgs e)
        {
            string xmlFile = @"C:\Configurare.xml";
            XMLParser xmlParser = new XMLParser(xmlFile);


            xmlParser.write("Configurare", "ServerIP", tbServerIP.Text);
            xmlParser.write("Configurare", "ServerPort", tbServerPort.Text);          
            xmlParser.write("Configurare", "FTPIp", tbFTPIP.Text);
            xmlParser.write("Configurare", "FTPUser", tbFTPUser.Text);
            xmlParser.write("Configurare", "FTPParola", mtFTPParola.Text);
            xmlParser.write("Configurare", "FTPPort", tbFTPPort.Text);
            xmlParser.write("Configurare", "Limba", cbLimba.SelectedItem.ToString());

            instance.limba = cbLimba.SelectedItem.ToString();
            FormDBMedical.FTPIp = tbFTPIP.Text;
            FormDBMedical.FTPUser = tbFTPUser.Text;
            FormDBMedical.FTPParola = mtFTPParola.Text;
            FormDBMedical.FTPPort = tbFTPPort.Text;

            FormDBMedical.ServerIP = tbServerIP.Text;
            FormDBMedical.ServerPort = tbServerPort.Text;



            limba = cbLimba.SelectedItem.ToString();
            Rename(limba);
            instance.rename();

        }
    }
}
